<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title th:text="${score.id != null ? '编辑成绩' : '添加成绩'} + ' - 学生成绩管理系统'">编辑成绩 - 学生成绩管理系统</title>
    <link rel="stylesheet" href="/css/layui.css">
    <link rel="stylesheet" href="/css/dp07.css">
</head>
<body>
<div class="layui-container">
    <div class="layui-row layui-margin-top20">
        <div class="layui-col-md6">
            <h2 th:text="${score.id != null ? '编辑成绩' : '添加成绩'}">编辑成绩</h2>
        </div>
        <div class="layui-col-md6" style="text-align: right;">
            <a href="/score/list" class="layui-btn layui-btn-primary">返回列表</a>
        </div>
    </div>
    
    <div class="layui-card layui-margin-top20">
        <div class="layui-card-body">
            <form class="layui-form" th:action="@{/score/save}" method="post">
                <input type="hidden" name="id" th:value="${score.id}">
                
                <div class="layui-form-item">
                    <label class="layui-form-label">学生</label>
                    <div class="layui-input-block">
                        <select name="studentId" lay-verify="required">
                            <option value="">-- 请选择学生 --</option>
                            <option th:each="student : ${students}" 
                                    th:value="${student.id}" 
                                    th:text="${student.name + ' (' + student.studentNo + ')'}"
                                    th:selected="${score.student != null && score.student.id == student.id}">
                                张三 (2023001)
                            </option>
                        </select>
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label class="layui-form-label">课程</label>
                    <div class="layui-input-block">
                        <select name="courseId" lay-verify="required">
                            <option value="">-- 请选择课程 --</option>
                            <option th:each="course : ${courses}" 
                                    th:value="${course.id}" 
                                    th:text="${course.courseName + ' (' + course.courseNo + ')'}"
                                    th:selected="${score.course != null && score.course.id == course.id}">
                                Java程序设计 (C001)
                            </option>
                        </select>
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label class="layui-form-label">成绩</label>
                    <div class="layui-input-block">
                        <input type="number" name="score" th:value="${score.score}" step="0.1" min="0" max="100" required lay-verify="required" placeholder="请输入成绩" autocomplete="off" class="layui-input">
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label class="layui-form-label">学期</label>
                    <div class="layui-input-block">
                        <input type="text" name="semester" th:value="${score.semester}" required lay-verify="required" placeholder="例如：2023-2024-1" autocomplete="off" class="layui-input">
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label class="layui-form-label">考试时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="examTime" th:value="${score.examTime}" placeholder="例如：2023-12-25" autocomplete="off" class="layui-input">
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea name="remark" th:text="${score.remark}" placeholder="请输入备注信息" class="layui-textarea"></textarea>
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit>保存</button>
                        <a href="/score/list" class="layui-btn layui-btn-primary">取消</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="/js/jquery-3.7.1.min.js"></script>
<script src="/js/layui.js"></script>
<script>
    layui.use(['layer', 'element', 'form'], function(){
        var layer = layui.layer;
        var element = layui.element;
        var form = layui.form;
        
        // 解决Thymeleaf与Layui表单元素冲突问题
        setTimeout(function(){
            form.render(); // 重新渲染表单元素
        }, 100);
    });
</script>
</body>
</html> 